package com.zhc.dejingapi.pojo.equipment;

import com.zhc.dejingapi.entity.QingEquipmentEntity;
import lombok.Data;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

@Data
public class QingEqCurrentStatusParam {
    //main_id	bigint
    //qingApplyId	bigint		数据ID
    private Long qingApplyId;
    //downBatchId	varchar	40	下载批次
    //qingRowCode	varchar	255	编号
    //qingApplyUser	varchar	80	申请人
    //qingApplyDate	datetime		申请日期
    //qingUpdateDate	datetime		更新日期
    //qingRowState	varchar	10	当前流程状态
    //eqId	bigint		设备ID
    private Long eqId;
    //eqCode	varchar	60	设备编码
    private String eqCode;
    //eqName	varchar	255	设备名称
    private String eqName;
    //eqStd	varchar	255	设备规格
    private String eqStd;
    //eqCurrStatus	varchar	60	设备当前状态
    private String eqCurrStatus;
    //eqRunStatus	varchar	60	设备运行状态
    private String eqRunStatus;
    //eqRunStateId	int		设备运行状态ID
    private Integer eqRunStateId;
    //useWorkShop	varchar	255	使用车间
    private String useWorkShop;
    //eqClass	varchar	255	设备分类
    private String eqClass;
    //eqStatus	varchar	60	状态
    private String eqStatus;
    //eqAvailCanEndTime	datetime		可用结束时间
    private String eqAvailCanEndTime;
    //eqWorkCanEndTime	datetime		任务累计结束时间
    private String eqWorkCanEndTime;
    //eqRunCanEndTime	datetime		预计结束时间
    private String eqRunCanEndTime;

    private Integer errCode;
    private String errMsg;
    private String lastRequestId;

    public void CopyEQEntity (QingEquipmentEntity entity)
    {
        this.eqId=entity.getMainId();
        //eqId
        //eqCode
        this.eqCode=entity.getEqCode();
        //eqName
        this.eqName=entity.getEqName();
        //eqStd
        this.eqStd=entity.getEqStd();
        //eqCurrStatus
        this.eqCurrStatus=entity.getEqStatus();
        //eqRunStatus

        //eqRunStateId

        //useWorkShop
        this.useWorkShop=entity.getUseWorkshop();
        //eqClass
        this.eqClass=entity.getEqClass();
        //eqStatus
        this.eqStatus=entity.getEqStatus();
        //eqAvailCanEndTime

        //eqWorkCanEndTime

        //eqRunCanEndTime
    }

    public void SaveToDB(JdbcTemplate mysqlJdbcTemplate){
        String strSql="select Count(*) from qing_eqcurrentstatus where eqId=?";
        int iHaveCount=mysqlJdbcTemplate.queryForObject(strSql,Integer.class,this.eqId);

        List<Object> listPara=new java.util.ArrayList<Object>();
        //eqCode	varchar	60	设备编码
        listPara.add(this.eqCode);
        //eqName	varchar	255	设备名称
        listPara.add(this.eqName);
        //eqStd	varchar	255	设备规格
        listPara.add(this.eqStd);
        //eqCurrStatus	varchar	60	设备当前状态
        listPara.add(this.eqCurrStatus);
        //eqRunStatus	varchar	60	设备运行状态
        listPara.add(this.eqRunStatus);
        //eqRunStateId	int		设备运行状态ID
        listPara.add(this.eqRunStateId);
        //useWorkShop	varchar	255	使用车间
        listPara.add(this.useWorkShop);
        //eqClass	varchar	255	设备分类
        listPara.add(this.eqClass);
        //eqStatus	varchar	60	状态
        listPara.add(this.eqStatus);
        //eqAvailCanEndTime	datetime		可用结束时间
        listPara.add(this.eqAvailCanEndTime);
        //eqWorkCanEndTime	datetime		任务累计结束时间
        listPara.add(this.eqWorkCanEndTime);
        //eqRunCanEndTime	datetime		预计结束时间
        listPara.add(this.eqRunCanEndTime);
        listPara.add(this.errCode);
        listPara.add(this.errMsg);
        listPara.add(this.lastRequestId);

        listPara.add(eqId);
//    private Integer errCode;
//    private String errMsg;
//    private String lastRequestId;
        if(iHaveCount>0){
            strSql="update qing_eqcurrentstatus set eqCode=?,\n" +
                    "eqName=?,\n" +
                    "eqStd=?,\n" +
                    "eqCurrStatus=?,\n" +
                    "eqRunStatus=?,\n" +
                    "eqRunStateId=?,\n" +
                    "useWorkShop=?,\n" +
                    "eqClass=?,\n" +
                    "eqStatus=?,\n" +
                    "eqAvailCanEndTime=?,\n" +
                    "eqWorkCanEndTime=?,\n" +
                    "eqRunCanEndTime=?,\n" +
                    "errCode=?,\n" +
                    "errMsg=?,\n" +
                    "lastRequestId=? \n" +
                    " where eqId=?";
        }
        else{

            strSql="INSERT  into qing_eqcurrentstatus(eqCode,\n" +
                    "eqName,\n" +
                    "eqStd,\n" +
                    "eqCurrStatus,\n" +
                    "eqRunStatus,\n" +
                    "eqRunStateId,\n" +
                    "useWorkShop,\n" +
                    "eqClass,\n" +
                    "eqStatus,\n" +
                    "eqAvailCanEndTime,\n" +
                    "eqWorkCanEndTime,\n" +
                    "eqRunCanEndTime," +
                    "errCode,\n" +
                    "errMsg,\n" +
                    "lastRequestId," +
                    "eqId) \n";
            strSql+="values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//    private Integer errCode;
//    private String errMsg;
//    private String lastRequestId;
        }
        mysqlJdbcTemplate.update(strSql,listPara.toArray());

    }


}
